<template>
  <!-- 
      4.Vue3.0中的响应式原理

   -->
  <h1>一个人的信息</h1>
  <h2 v-show="person.name">姓名: {{ person.name }}</h2>
  <h2>年龄: {{ person.age }}</h2>
  <h2 v-show="person.sex">性别: {{ person.sex }}</h2>
  <h2>工作种类: {{ person.job.type }}</h2>
  <h2>工作薪水: {{ person.job.salary }}</h2>
  <h2>测试的数据: {{ person.job.a.b.c }}</h2>
  <h2>爱好: {{ hobby }}</h2>
  <button @click="changeInfo">修改信息</button>
  <button @click="addSex">添加一个sex属性</button>
  <button @click="deleteName">删除一个name属性</button>
</template>

<script>
import { ref, reactive } from 'vue'
export default {
  name: 'App',
  setup () {
    // 数据
    let person = reactive({
      name: '张三',
      age: 18,
      job: {
      type: '前端',
        salary: '30K',
        a: {
          b: {
            c: 666
          }
        }
      },
      hobby: ['抽烟', '喝酒', '烫头']
    })

    // 方法
    function changeInfo () {
      //ref定义的数据
      person.name = 'aaa'
      person.age =48
      //reactive定义的数据
      console.log(person.ob)
      person.job.type = 'ui'
      person.job.salary = '40K'
      person.job.a.b.c = 999
      person.hobby[0] = '学习'
    }
    function addSex () {
      person.sex = '男'
    }
    function deleteName () {
      delete person.name
    }

    //返回一个对象(常用)
    return {
      person,
      addSex,
      deleteName,
      changeInfo
    }
  }
}
</script>

<style>

</style>
